<script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="/ueditor/lang/zh-cn/zh-cn.js"></script>
<style>
    #login-button{
        background: #286090!important;
        color: white!important;
        border: 1px solid #286090!important;
        border-radius: 3px;
    }
    .addSdk {
        text-decoration: none;
        background: #337ab7;
        color: white;
        padding: 5px 10px;
        border-radius: 4px;
        margin:10px 0;
        display: inline-block;
    }
    .sdkList{
        list-style: none;
        margin:0;
    }
    .sdkList li span{
        margin-right: 10px;
    }
    .sdkList li .sdk_sdk,.integral{
        width: 100px;
    }
    .up_file {  position:relative;  text-decoration:none; text-indent:0;margin-top: -10px}
    .up_file input { position:absolute; right:0; top:0; opacity:0; width: 100%;}
</style>
<div class="span10">
    <div style="margin-bottom: 20px;">
        <a href="/index/index">首页</a>
        <span >&gt;</span>
        <span>课程管理</span>
        <span >&gt;</span>
        <span>添加</span>
    </div>
    <form class="form" method="post" action="<?php echo baseUrl."/content/classes/add"?>" enctype="multipart/form-data">
        <table>
            <tr>
                <td>课程名称 *</td>
                <td ><input type="text" style="width: 600px;" name="name" placeholder="" value="<?php echo isset($data)? $data['name']:''?>"/></td>
            </tr>
            <?php if(isset($data)) {
                $str = '<tr>';
                $str .= '<td>原图片:</td>';
                $str .= '<td>';
                $pic = $data['pic'];
                $str .= "<input name='pic' type='text' value='" . $pic . "'></td></tr>";
                echo $str;
            } ?>

            <tr>
                <td>封面图 *:</td>
                <td>
                    <input id="file" type="file" name="pic" >
                </td>
            </tr>
            <tr>
                <td>类别 *:</td>
                <td>
                    <select name="cate">
                        <option value ="">请选择班级</option>
                        <option value ="1" <?php echo isset($data)&& $data['cate']=="1" ?  'selected':''?>>大班课</option>
                        <option value ="2" <?php echo isset($data)&& $data['cate']=="2" ?  'selected':''?>>小班课</option>
                        <option value ="3" <?php echo isset($data)&& $data['cate']=="3" ?  'selected':''?>>单项课</option>
                        <option value ="4" <?php echo isset($data)&& $data['cate']=="4" ?  'selected':''?>>录播课</option>
                        <option value ="5" <?php echo isset($data)&& $data['cate']=="5" ?  'selected':''?>>直播课</option>
                        <option value ="6" <?php echo isset($data)&& $data['cate']=="6" ?  'selected':''?>>1对1课</option>
                        <option value ="7" <?php echo isset($data)&& $data['cate']=="7" ?  'selected':''?>>封闭班</option>
                        <option value ="8" <?php echo isset($data)&& $data['cate']=="8" ?  'selected':''?>>热门课程</option>
                        <option value ="9" <?php echo isset($data)&& $data['cate']=="9" ?  'selected':''?>>寒暑假封闭班</option>

                    </select>
                </td>
            </tr>
            <tr>
                <td>班型 *:</td>
                <td>
                    <select name="class">
                        <option value ="">请选择班型</option>
                        <option value ="1" <?php echo isset($data)&& $data['class']=="1" ?  'selected':''?>>小班课</option>
                        <option value ="2" <?php echo isset($data)&& $data['class']=="2" ?  'selected':''?>>中小班</option>
                        <option value ="3" <?php echo isset($data)&& $data['class']=="3" ?  'selected':''?>>一对一课</option>

                    </select>
                </td>
            </tr>

            <tr>
                <td>单项:</td>
                <td>
                    <select name="subject">
                        <option value ="">请选择科目</option>
                        <option value ="1" <?php echo isset($data)&& $data['subject']=="1" ?  'selected':''?>>听力</option>
                        <option value ="2" <?php echo isset($data)&& $data['subject']=="2" ?  'selected':''?>>口语</option>
                        <option value ="3" <?php echo isset($data)&& $data['subject']=="3" ?  'selected':''?>>阅读</option>
                        <option value ="4" <?php echo isset($data)&& $data['subject']=="4" ?  'selected':''?>>写作</option>
                     </select>
                </td>
            </tr>
            <tr>
                <td>课程目标分:</td>
                <td>
                    <select name="score">
                        <option value ="">请选择分数</option>
                        <option value ="1" <?php echo isset($data)&& $data['score']=="1" ?  'selected':''?>>5.0</option>
                        <option value ="2" <?php echo isset($data)&& $data['score']=="2" ?  'selected':''?>>5.5</option>
                        <option value ="3" <?php echo isset($data)&& $data['score']=="3" ?  'selected':''?>>6.0</option>
                        <option value ="4" <?php echo isset($data)&& $data['score']=="4" ?  'selected':''?>>6.5</option>
                        <option value ="5" <?php echo isset($data)&& $data['score']=="5" ?  'selected':''?>>7分及以上</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>课时 *</td>
                <td ><input type="text" style="width: 600px;" name="duration" placeholder="" value="<?php echo isset($data)? $data['duration']:''?>"/></td>
            </tr>
            <tr>
                <td>授课教师：</td>
                <td><input type="text" style="width: 600px;" name="teacher" placeholder="格式：kevin,amanda,kevin 符号为英文" value="<?php echo isset($data)? $data['teacher']:''?>"/></td>
            </tr>
<!--            <tr>-->
<!--                <td>课程上架:</td>-->
<!--                <td>-->
<!--                    <select name="isShow">-->
<!--                        <option value ="1" --><?php //echo isset($data)&& $data['isShow']=="1" ?  'selected':''?><!--是</option>-->
<!--                        <option value ="0" --><?php //echo isset($data)&& $data['isShow']=="0" ?  'selected':''?><!--否</option>-->
<!--                    </select>-->
<!--                </td>-->
<!--            </tr>-->
            <tr>
                <td>是否推荐到热门:</td>
                <td>
                    <select name="isHot">
                        <option value ="1" <?php echo isset($data)&& $data['isHot']=="1" ?  'selected':''?>>是</option>
                        <option value ="0" <?php echo isset($data)&& $data['isHot']=="0" ?  'selected':''?>>否</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>是否置顶:</td>
                <td>
                    <select name="isTop">
                        <option value ="1" <?php echo isset($data)&& $data['isTop']=="1" ?  'selected':''?>>是</option>
                        <option value ="0" <?php echo isset($data)&& $data['isTop']=="0" ?  'selected':''?>>否</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>所属客户端:</td>
                <td>
                    <select name="classesPort">
                        <option value ="1" <?php echo isset($data)&& $data['classesPort']=="1" ?  'selected':''?>>PC</option>
                        <option value ="2" <?php echo isset($data)&& $data['classesPort']=="2" ?  'selected':''?>>APP</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>APP展示位置:</td>
                <td>
                    <select name="showType" onchange="changeTag()">
                        <option value ="0" <?php echo isset($data)&& $data['showType']=="0" ?  'selected':''?>>无</option>
                        <option value ="1" <?php echo isset($data)&& $data['showType']=="1" ?  'selected':''?>>推荐课程</option>
                        <option value ="2" <?php echo isset($data)&& $data['showType']=="2" ?  'selected':''?>>热门课程</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>APP课程标签:</td>
                <td>
                    <select name="classesTag">
                    </select>
                </td>
            </tr>
            <?php if(isset($data)) {
                $str = '<tr>';
                $str .= '<td>课程封面图原图片:</td>';
                $str .= '<td>';
                $course_image = $data['course_image'];
                $str .= "<input name='course_image' type='text' value='" . $course_image . "'></td></tr>";
                echo $str;
            } ?>

            <tr>
                <td>课程封面图片：</td>
                <td><input id="file" type="file" name="course_image" ></td>
            </tr>
            <tr>
                <td>课程标签：</td>
                <td><input type="text" name="course_tag" placeholder="" value="<?php echo isset($data)? $data['course_tag']:''?>"/></td>
            </tr>
            <?php if(isset($data)) {
                $str = '<tr>';
                $str .= '<td>wap课程详情原图片:</td>';
                $str .= '<td>';
                $course_description1 = $data['course_description1'];
                $str .= "<input name='course_description1' type='text' value='" . $course_description1 . "'></td></tr>";
                echo $str;
            } ?>

            <tr>
                <td>wap课程详情图片：</td>
                <td><input id="file" type="file" name="course_description1" ></td>
            </tr>

            <?php if(isset($data)) {
                $str = '<tr>';
                $str .= '<td>app课程详情原图片:</td>';
                $str .= '<td>';
                $course_description2 = $data['course_description2'];
                $str .= "<input name='course_description2' type='text' value='" . $course_description2 . "'></td></tr>";
                echo $str;
            } ?>

            <tr>
                <td>app课程详情图片：</td>
                <td><input id="file" type="file" name="course_description2" ></td>
            </tr>

            <?php if(isset($data)) {
                $str = '<tr>';
                $str .= '<td>pc课程详情原图片:</td>';
                $str .= '<td>';
                $course_description3 = $data['course_description3'];
                $str .= "<input name='course_description3' type='text' value='" . $course_description3 . "'></td></tr>";
                echo $str;
            } ?>

            <tr>
                <td>pc课程详情图片：</td>
                <td><input id="file" type="file" name="course_description3" ></td>
            </tr>
            <tr>
                <td>试听sdk：</td>
                <td><input type="text" style="width: 600px;" name="url" placeholder="" value="<?php echo isset($data)? $data['url']:''?>"/></td>
            </tr>
            <tr>
                <td>视频集：</td>
                <td>
                    <ul class="sdkList" num="<? echo $classesSdk?count($classesSdk):0?>">
                        <?php
                            if($classesSdk){
                                foreach ($classesSdk as $k=>$v){?>
                            <li>
                                <span><input type="text" name="classesSdk[<?php echo $k?>][sdk]" class="sdk_sdk" value="<?php echo $v['sdk']?>" placeholder="视频SDK"/></span>
                                <span><input type="text" name="classesSdk[<?php echo $k?>][pic]" value="<?php echo $v['pic']?>" class="sdk_pic"><a href="javascript:;" class="up_file">上传封面<input type="file" onchange="upImage(this)" accept="image/*"/></a></span>
                                <span><input type="radio" name="classesSdk[<?php echo $k?>][type]" value="1" <?php echo $v['type']==1?'checked':''?>>免费 <input type="radio" name="classesSdk[<?php echo $k?>][type]" value="2" <?php echo $v['type']==2?'checked':''?>>付费</span>
                                <span>消耗蜜糖：<input type="text" name="classesSdk[<?php echo $k?>][integral]" class="integral" value="<?php echo $v['integral']?>"></span>
                                <span><a href="javascript:;" class="delSdk">删除</a></span>
                                <br>
                            </li>
                        <?php }}?>
                    </ul>
                    <a class="addSdk" href="javascript:;" onclick="addTag()">添加</a>
                </td>
            </tr>
            <!-- <tr>
                <td width="80px">适合人群:</td>
                <td>
                    <textarea type="text/plain" id="editor" name="student" placeholder="适合人群" style="height:300px;width:70%"><?php echo isset($data)? $data["student"]:''?></textarea>
                </td>
            </tr> -->

            <tr>
                <td width="80px">适合人群:</td>
                <td>
                    <textarea type="text/plain"   name="systemPeople" placeholder="适合人群" style="height:200px;width:60%"><?php echo isset($data)? $data["systemPeople"]:''?></textarea>
                </td>
            </tr>
            <tr>
                <td width="80px">课程内容:</td>
                <td>
                    <textarea type="text/plain"  name="systemContent" placeholder="入学要求" style="height:200px;width:60%"><?php echo isset($data)? $data["systemContent"]:''?></textarea>
                </td>
            </tr>
            <tr>
                <td width="80px">上课周期:</td>
                <td>
                    <textarea type="text/plain"  name="systemCourse" placeholder="上课周期" style="height:200px;width:60%"><?php echo isset($data)? $data["systemCourse"]:''?></textarea>
                </td>
            </tr>

            <tr>
                <td>授课名师：</td>
                <td><input type="text"  style="width: 600px;" name="systemTeacher" placeholder="填写老师id" value="<?php echo isset($data)? $data['systemTeacher']:''?>"/></td>
            </tr>
            <tr>
                <td width="80px">服务内容:</td>
                <td>
                    <textarea type="text/plain"  name="systemServe" placeholder="服务内容" style="height:200px;width:60%"><?php echo isset($data)? $data["systemServe"]:''?></textarea>
                </td>
            </tr>
            <tr>
                <td>价格 *：￥</td>
                <td><input type="text"  style="width: 600px;" name="price" placeholder="课程价格" value="<?php echo isset($data)? $data['price']:''?>"/></td>
            </tr>
            <tr>
                <td>原价：￥</td>
                <td><input type="text"  style="width: 600px;" name="originalPrice" placeholder="课程价格" value="<?php echo isset($data)? $data['originalPrice']:''?>"/></td>
            </tr>
            <tr>
                <td>摘要 *：</td>
                <td>
                    <input type="text" id="summary" style="width: 600px;" name="summary" placeholder="摘要"  value="<?php echo isset($data) ? $data['summary'] : ''?>"/>
                </td>
            </tr>
            <tr>
                <td>关键词 *：</td>
                <td>
                    <input type="text" id="keywords" style="width: 600px;" name="keywords" placeholder="关键词"  value="<?php echo isset($data) ? $data['keywords'] : '' ?>"/>
                </td>
            </tr>
            <tr>
                <td>专属服务：</td>
                <td>
                    <textarea type="text/plain"  name="service" placeholder="专属服务" style="height:200px;width:60%"><?php echo isset($data)? $data["service"]:''?></textarea>
                </td>
            </tr>
            <tr>
                <td>课程设置：</td>
                <td>
                    <textarea type="text/plain"  name="structure" placeholder="课程设置" style="height:200px;width:60%"><?php echo isset($data)? $data["structure"]:''?></textarea>
                </td>
            </tr>
            <tr>
                <td>课程介绍 *：</td>
                <td>
                    <textarea type="text/plain" id="intro" name="introduction" placeholder="课程介绍" style="height:300px;width:78%"><?php echo isset($data) ? $data['introduction'] : '' ?></textarea>
                </td>
            </tr>
            <tr>
                <td>开课时间：</td>
                <td>
                    <input type="text/plain"  name="classTime" placeholder="开课时间" value="<?php echo isset($data)? $data['classTime']:''?>"/>
                </td>
            </tr>
            <tr>
                <td>上传者</td>
                <td ><input type="text" style="width: 600px;" name="author" placeholder="" value="<?php echo isset($data)? $data['author']:''?>"/></td>
            </tr>
            <tr>
                <td>关联课程id</td>
                <td ><input type="text" style="width: 600px;" name="relatedId" placeholder="" value="<?php echo isset($data)? $data['relatedId']:''?>"/></td>
            </tr>
            <tr>
                <td>浏览量</td>
                <td ><input type="text" style="width: 600px;" name="viewCount" placeholder="" value="<?php echo isset($data)? $data['viewCount']:''?>"/></td>
            </tr>

            <tr>
                <td colspan="2" align="center"> <button type="submit" id="login-button"><?php echo isset($data)? '编辑':'添加'?>课程</button></td>
            </tr>
            <input type="hidden" name='id' value="<?php echo isset($data)? $data['id']:''?>"/>
            <input type="hidden" name="_csrf" value="<?=Yii::$app->request->getCsrfToken()?>" />
        </table>
    </form>
</div>
<script>
    //实例化编辑器
    var ue = UE.getEditor('editor');
    var plan = UE.getEditor('plan');
    var intro = UE.getEditor('intro');

    var cate = <?php echo $classesTag?>;
    var tagVal = '<?php echo isset($data)?$data['classesTag']:''?>';
    function showTypeChange(type) {
        var html = '<option value ="0">无</option>';
        if(type){
            $.each(cate,function (k,v) {
                var selected = '';
                if(v['type']==type){
                    if(tagVal==v['id']) selected='selected';
                    html += '<option value ="'+v['id']+'"  '+selected+'>'+v['name']+'</option>';
                }
            })
        }
        $('select[name="classesTag"]').html(html);
    }
    function changeTag() {
        showTypeChange($('select[name="showType"]').val());
    }
    changeTag();

    $('.addSdk').click(function () {
        var num = $('.sdkList').attr('num');
        var next = parseInt(num)+parseInt(1);
        var html = `<li>
            <span><input type="text" name="classesSdk[${num}][sdk]" class="sdk_sdk" value="" placeholder="视频SDK"/></span>
            <span><input type="text" name="classesSdk[${num}][pic]" value="" class="sdk_pic"><a href="javascript:;" class="up_file">上传封面<input type="file" onchange="upImage(this)" accept="image/*"/></a></span>
            <span><input type="radio" name="classesSdk[${num}][type]" value="1">免费 <input type="radio" name="classesSdk[${num}][type]" value="2">付费</span>
            <span>消耗蜜糖：<input type="text" name="classesSdk[${num}][integral]" class="integral" value=""></span>
            <span><a href="javascript:;" class="delSdk">删除</a></span>
            <br>
            </li>`;
        $('.sdkList').append(html);
        $('.sdkList').attr('num',next);
    })
    $('.sdkList').delegate('.delSdk','click',function () {
        $(this).parents('li').remove();
    })

    function upImage(obj) {
        var data = new FormData();
        var file = $(obj).get(0).files[0];
        if(!file){
            return false;
        }
        data.append('file', file);
        $.ajax({
            type: 'POST',
            url: "/content/api/up-image",
            dataType: "json",
            contentType:false,
            processData: false,
            data: data,
            success: function(res) {
                alert(res.message)
                if(res.code == 1){
                    $(obj).parents('span').find('.sdk_pic').val(res.path);
                }
            },
            error: function(e){
                alert('系统错误，请重试')
            },
        });
    }
</script>